- name: push packages out
  hosts: packages:packages-stg
  user: root
  vars_files: 
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  vars:
    testing: False
  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

  tasks:
  - name: clean all metadata {%if testing%}(with infrastructure-testing on){%endif%}
    command: dnf clean all {%if testing%} --enablerepo=infrastructure-tags-stg {%endif%}
    check_mode: no
  - name: dnf update fedora-packages packages from main repo
    dnf: name="fedora-packages" state=latest
    when: not testing
  - name: dnf update fedora-packages packages from testing repo
    dnf: name="fedora-packages" state=latest enablerepo=infrastructure-tags-stg
    when: testing

- name: verify the config and restart it
  hosts: packages:packages-stg
  user: root
  vars_files: 
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

  pre_tasks:
  - name: tell nagios to shush
    nagios: action=downtime minutes=60 service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.phx2.fedoraproject.org
    ignore_errors: true

  roles:
  - role: packages3/web

  post_tasks:
  - service: name="fedmsg-hub" state=stopped
  - service: name="httpd" state=stopped
  # TODO -- do any DB maintenance steps we need to do here..
  - service: name="httpd" state=started
  - service: name="fedmsg-hub" state=started

  - name: tell nagios to unshush
    nagios: action=unsilence service=host host={{ inventory_hostname_short }}{{ env_suffix }}
    delegate_to: noc01.phx2.fedoraproject.org
    ignore_errors: true
